﻿using System;

namespace TopHero
{
    public struct Vector2
    {
        public Vector2(float x, float y)
        {
            this.x = x;
            this.y = y;
        }

        public float x;

        public float y;

        public static Vector2 operator +(Vector2 a, Vector2 b) => new Vector2(a.x + b.x, a.y + b.y);

        public static Vector2 operator -(Vector2 a, Vector2 b) => new Vector2(a.x - b.x, a.y - b.y);

        public static Vector2 operator *(Vector2 a, Vector2 b) => new Vector2(a.x * b.x, a.y * b.y);

        public static Vector2 operator /(Vector2 a, Vector2 b) => new Vector2(a.x / b.x, a.y / b.y);

        public static Vector2 operator -(Vector2 a) => new Vector2(-a.x, -a.y);

        public static Vector2 operator *(Vector2 a, float d) => new Vector2(a.x * d, a.y * d);

        public static Vector2 operator *(float d, Vector2 a) => new Vector2(a.x * d, a.y * d);

        public static Vector2 operator /(Vector2 a, float d) => new Vector2(a.x / d, a.y / d);

        public static bool operator ==(Vector2 lhs, Vector2 rhs)
        {
            float num1 = lhs.x - rhs.x;
            float num2 = lhs.y - rhs.y;
            return (double) num1 * (double) num1 + (double) num2 * (double) num2 < 9.99999943962493E-11;
        }

        public static bool operator !=(Vector2 lhs, Vector2 rhs) => !(lhs == rhs);

        public override int GetHashCode() => this.x.GetHashCode() ^ this.y.GetHashCode() << 2;

        public override bool Equals(object other) => other is Vector2 other1 && this.Equals(other1);

        private static readonly Vector2 zeroVector = new Vector2(0.0f, 0.0f);
        private static readonly Vector2 oneVector = new Vector2(1f, 1f);
        private static readonly Vector2 upVector = new Vector2(0.0f, 1f);
        private static readonly Vector2 downVector = new Vector2(0.0f, -1f);
        private static readonly Vector2 leftVector = new Vector2(-1f, 0.0f);
        private static readonly Vector2 rightVector = new Vector2(1f, 0.0f);
        public static Vector2 zero => Vector2.zeroVector;
        public static Vector2 one => Vector2.oneVector;
        public static Vector2 up => Vector2.upVector;
        public static Vector2 down => Vector2.downVector;
        public static Vector2 left => Vector2.leftVector;
        public static Vector2 right => Vector2.rightVector;
        
        public float sqrMagnitude => (float) ((double) this.x * (double) this.x + (double) this.y * (double) this.y);
        public float magnitude => (float) Math.Sqrt((double) this.x * (double) this.x + (double) this.y * (double) this.y);
        
        public void Normalize()
        {
            float magnitude = this.magnitude;
            if ((double) magnitude > 9.99999974737875E-06)
                this = this / magnitude;
            else
                this = Vector2.zero;
        }

        public Vector2 normalized
        {
            get
            {
                Vector2 vector2 = new Vector2(this.x, this.y);
                vector2.Normalize();
                return vector2;
            }
        }
    }
}